package team.first.movieapiv3pro.controller;

import io.swagger.annotations.ApiOperation;
import org.neo4j.ogm.cypher.query.SortOrder;
import org.neo4j.ogm.session.Session;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import team.first.movieapiv3pro.movie.GenreNode;
import team.first.movieapiv3pro.util.SessionFactoryUtil;
import team.first.movieapiv3pro.vo.ApiResponse;

import java.util.Collection;

/**
 * @Author: HAPPY
 * @Project_name: project
 * @Package_name: team.first.movieapiv3.controller
 * @Date: 2021/12/9 16:18
 * @Description:
 */
@RestController
public class GenreController {

    /**
     * 1.1 获取全部电影类型信息
     * 接口地址：GET /api/v1/genres
     */
    @ApiOperation("1.1 GET: 获取全部电影类型信息")
    @GetMapping("/api/v3/genres")
    public ApiResponse<Collection<GenreNode>> genres() {
        ApiResponse<Collection<GenreNode>> apiResponse = new ApiResponse<>();
        try {
            Session session = SessionFactoryUtil.getSession("team.first.movieapiv3pro.movie");

            // 根据id升序排序输出
            Collection<GenreNode> genreNodeCollection = session.loadAll(GenreNode.class, new SortOrder("id"));

            apiResponse.setCode(200).setSuccess(true).setMessage("请求成功").setData(genreNodeCollection);
        } catch (Exception e) {
            apiResponse.setCode(500).setSuccess(false).setMessage("请求失败").setData(null);
        }
        return apiResponse;
    }


}
